package yannan.voiplock4ble.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import org.greenrobot.greendao.database.Database;

import yannan.voiplock4ble.bean.DaoMaster;
import yannan.voiplock4ble.bean.LocalDBTimeDao;
import yannan.voiplock4ble.bean.LockBeanDao;
import yannan.voiplock4ble.bean.LockKeyBeanDao;
import yannan.voiplock4ble.bean.LockKeyTempDao;
import yannan.voiplock4ble.bean.LockRecordBeanDao;
import yannan.voiplock4ble.bean.PwdKeyBeanDao;
import yannan.voiplock4ble.bean.UserAccountDao;
import yannan.voiplock4ble.bean.UserBeanDao;
import yannan.voiplock4ble.bean.VeinKeyBeanDao;

import static yannan.voiplock4ble.db.AbstractDBHelper.DATABASE_NAME;


/**
 * 说明：数据库升级
 * 作者：mainTel
 * 时间：2016/11/4 13:47
 * 备注：
 */
public class MyUpOpenHelper extends DaoMaster.OpenHelper {

    Context context;

    public MyUpOpenHelper(Context context, String name) {
        super(context, name);
    }

    public MyUpOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory) {
        super(context, name, factory);
    }

    @Override
    public void onUpgrade(Database db, int oldVersion, int newVersion) {
        super.onUpgrade(db, oldVersion, newVersion);
        Log.e("MyUpOpenHelper", "oldVersion:" + oldVersion);
        Log.e("MyUpOpenHelper", "newVersion:" + newVersion);

//        if (oldVersion <= 7) {
//            String path = context.getDatabasePath(DATABASE_NAME).getPath();
//            net.sqlcipher.database.SQLiteDatabase oldDB = net.sqlcipher.database.SQLiteDatabase.openOrCreateDatabase(path, "", null);
//        } else {
        MigrationHelper.migrate(db, LocalDBTimeDao.class,
                LockBeanDao.class,
                LockKeyBeanDao.class,
                LockKeyTempDao.class,
                LockRecordBeanDao.class,
                PwdKeyBeanDao.class,
                VeinKeyBeanDao.class,
                UserAccountDao.class,
                UserBeanDao.class);
//        }
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
//        boolean ifNotExists = true;
//        LocalDBTimeDao.createTable(new StandardDatabase(db), ifNotExists);
//        LockBeanDao.createTable(new StandardDatabase(db), ifNotExists);
//        LockKeyBeanDao.createTable(new StandardDatabase(db), ifNotExists);
//        LockKeyTempDao.createTable(new StandardDatabase(db), ifNotExists);
//        LockRecordBeanDao.createTable(new StandardDatabase(db), ifNotExists);
//        PwdKeyBeanDao.createTable(new StandardDatabase(db), ifNotExists);
//        UserAccountDao.createTable(new StandardDatabase(db), ifNotExists);
//        UserBeanDao.createTable(new StandardDatabase(db), ifNotExists);
//        VeinKeyBeanDao.createTable(new StandardDatabase(db), ifNotExists);


    }
}
